package com.front.managementfront.banner.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.front.managementfront.banner.entity.HktsBanner;
import com.front.managementfront.banner.service.IHktsBannerService;
import com.front.managementfront.utils.CustomPageUtils;
import com.hkts.management.common.utils.CustomPage;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hml
 * @since 2021-04-22
 */
@RestController
@RequestMapping("/front/hktsBanner")
@Api(tags = "banner接口")
public class HktsBannerController {
    private final Logger logger = LoggerFactory.getLogger(HktsBannerController.class);

    @Autowired
    public IHktsBannerService iHktsBannerService;

    /**
     * 分页查询数据
     *
     * @param page       分页信息
     * @param hktsBanner 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsBannerPageList")
    @ApiOperation(value = "banner分页接口")
    public Result<CustomPage<List<HktsBanner>>> getHontUserList(Page<HktsBanner> page, HktsBanner hktsBanner) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsBannerService.selectPage(page, hktsBanner)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsBanner 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsBannerSave")
    @ApiOperation(value = "banner新增和修改接口")
    public Result<Object> hktsBannerSave(HktsBanner hktsBanner) {
        iHktsBannerService.saveOrUpdate(hktsBanner);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsBannerGetById")
    @ApiOperation(value = "根据id获取banner数据")
    public Result<Object> hktsBannerGetById(String id) {
        HktsBanner byId = iHktsBannerService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsBannerDelete")
    @ApiOperation(value = "根据id删除")
    public Result<Object> hontUserDelete(String id) {
        iHktsBannerService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsBannerBatchDelete")
    @ApiOperation(value = "批量删除")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsBannerService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

}
